package com.lk.server.expose;

import cn.hutool.http.HttpUtil;
import com.lk.server.config.NamicServiceConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 程序关闭时从注册中心移除
 * 这里暂时使用主动移除,没有使用心跳来检查
 *
 * @author kun.li
 */
@Component
@Slf4j
public class ExposeCloseService implements DisposableBean {
    @Autowired
    private NamicServiceConfig namicServiceConfig;

    @Override
    public void destroy() throws Exception {
        // 发送
        String get = HttpUtil.get(namicServiceConfig.getAddress() + "/register/removeService?serviceName="+namicServiceConfig.getServiceName());
        log.info("移除:{}", get);
    }
}
